import { Logger } from "@/utils/Logger";

export class PrivacyConfig {

    public static Config_Name:string = "privacy"

    public id:number;
    public group:number;
    public groupname:string;
    public subtype:number;
    public subtypename:string;

    public static configMap: Map<number, PrivacyConfig> = new Map<number, PrivacyConfig>();

    private static obj2Config(obj: object) {
        let config: PrivacyConfig = new PrivacyConfig();
        for (let key in obj) {
            if (typeof (obj[key]) !== "function")
                config[key] = obj[key];
        }
        return config;
    }

    public static json2Config(jsonObj: Object) {
        Object.keys(jsonObj).forEach((key) => {
            let config: PrivacyConfig = this.obj2Config(jsonObj[key]);
            this.configMap.set(config.id, config);
        });
        // Logger.log("PrivacyConfig==", this.configMap)
    }

    public static getMainGroupList(){
        let groupList:Array<PrivacyConfig> = [];
        this.configMap.forEach((value: PrivacyConfig, key: number) => {
            groupList[value.group-1] = value;
        });
        return groupList;
    }


    public static getSubGroupList(groupId:number){
        let groupList:Array<PrivacyConfig> = [];
        this.configMap.forEach((value: PrivacyConfig, key: number) => {
            if(value.group == groupId){
                groupList.push(value);
            }
        });
        return groupList;
    }

}